﻿// <copyright file="ArmyViewOwner.cs" company="Gravity Age Studios">
// Code released under the MIT license (see License.txt).
// </copyright>
// <author>Vicente Cartas Espinel</author>
// <email>vicente.cartas@gmail.com</email>
namespace LightSwitchApplication
{
    using System.Collections.Generic;
    using Microsoft.LightSwitch;
    using Microsoft.LightSwitch.Presentation.Extensions;

    public partial class ArmyViewOwner
    {
        partial void ArmyViewOwner_InitializeDataWorkspace(List<IDataService> saveChangesTo)
        {
            this.DisplayName = string.Format("View {0} details", this.Army.Name);
        }

        #region View Character

        partial void ViewCharacterDetails_CanExecute(ref bool result)
        {
            result = this.Characters.SelectedItem != null;
        }

        partial void ViewCharacterDetails_Execute()
        {
            this.Application.ShowCharacterAddEditOwner(this.Characters.SelectedItem.Id);
        }

        #endregion

        #region Edit LandUnit

        partial void LandUnitsEditSelected_CanExecute(ref bool result)
        {
            result = this.LandUnits.SelectedItem != null;
        }

        partial void LandUnitsEditSelected_Execute()
        {
            this.FindControl("ModalWindowLandUnit").DisplayName = string.Format("Edit {0}", this.LandUnits.SelectedItem.Name);
            this.OpenModalWindow("ModalWindowLandUnit");
        }

        partial void SubmitModalWindowLandUnit_Execute()
        {
            this.CloseModalWindow("ModalWindowLandUnit");
        }

        partial void CancelModalWindowLandUnit_CanExecute(ref bool result)
        {
            this.CloseModalWindow("ModalWindowLandUnit");
            this.LandUnits.SelectedItem.Details.DiscardChanges();
        }

        #endregion

        #region Edit SeaUnit

        partial void SeaUnitsEditSelected_CanExecute(ref bool result)
        {
            result = this.SeaUnits.SelectedItem != null;
        }

        partial void SeaUnitsEditSelected_Execute()
        {
            this.FindControl("ModalWindowSeaUnit").DisplayName = string.Format("Edit {0}", this.SeaUnits.SelectedItem.Name);
            this.OpenModalWindow("ModalWindowSeaUnit");
        }

        partial void SubmitModalWindowSeaUnit_Execute()
        {
            this.CloseModalWindow("ModalWindowSeaUnit");
        }

        partial void CancelModalWindowSeaUnit_Execute()
        {
            this.CloseModalWindow("ModalWindowSeaUnit");
            this.SeaUnits.SelectedItem.Details.DiscardChanges();
        }

        #endregion
    }
}